package com.cham.user.controller;

import com.cham.enums.ChamSysCodeEnum;
import com.cham.user.dto.UserInfo;
import com.cham.user.entity.User;
import com.cham.user.service.UserService;
import com.cham.utils.TokenUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;

/**
 * @author Howl-Xu
 * @version 1.0.0
 * @Description: 请描述一下这个类文件吧
 * @createTime 2020年03月14日 10:39:00
 */
@Controller
@RequestMapping("/user")
public class UserController {
    @Autowired
    private UserService userService;

    @GetMapping("/isUserExist")
    @ResponseBody
    public boolean isUserExist(String account, String password){
        User user = userService.getUserByAccountAndPassword(account,password);
        if(user!=null){
            return true;
        }else{
            return false;
        }
    }

    @GetMapping("/getUserByAccountAndPassword")
    @ResponseBody
    public User getUserByAccountAndPassword(String account, String password){
        return userService.getUserByAccountAndPassword(account,password);
    }

    //根据用户的uuid查找用户头像
    @GetMapping("/getUserHeadImgByUUID")
    @ResponseBody
    public String getUserHeadImgByUUID(String uuid){
        return userService.getUserHeadImgByUUID(uuid);
    }

    //根据用户的uuid查找用户头像
    @GetMapping("/getUserInfoByUserUUID")
    @ResponseBody
    public UserInfo getUserInfoByUserUUID(String uuid){
        return userService.getUserInfoByUserUUID(uuid);
    }

    @PostMapping("/register")
    @ResponseBody
    public ChamSysCodeEnum register(@RequestBody User user){
        userService.register(user);
        return ChamSysCodeEnum.USER_REGISTER_SUCCESS;
    }


    @PostMapping("/updateUserInfo")
    @ResponseBody
    public ChamSysCodeEnum updateUserInfo(@RequestBody UserInfo userInfo){
        userService.updateUserInfo(userInfo);
        return ChamSysCodeEnum.SAVE_USERINFO_SUCCESS;
    }

    @PostMapping("/updateHeadImg")
    @ResponseBody
    public ChamSysCodeEnum updateHeadImg(@RequestBody UserInfo userInfo){
        userService.updateHeadImg(userInfo);
        return ChamSysCodeEnum.UPLOAD_HEADIMG_SUCCESS;
    }
}
